package com.qbccn.usercenter.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qbccn.usercenter.domain.UcUser;
import com.qbccn.usercenter.domain.UcUserRole;
import com.qbccn.usercenter.dto.ResponsePageResult;
import com.qbccn.usercenter.dto.ResponseResult;
import com.qbccn.usercenter.mapper.UcSystemMenuMapper;
import com.qbccn.usercenter.mapper.UcUserMapper;
import com.qbccn.usercenter.mapper.UcUserRoleMapper;
import com.qbccn.usercenter.service.UserService;
import com.qbccn.usercenter.vo.TreeListVo;
import com.qbccn.usercenter.vo.UserFindListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author linke
 * @date 2020/5/23 21:01
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UcUserMapper ucUserMapper;
    @Autowired
    private UcUserRoleMapper ucUserRoleMapper;
    @Autowired
    private UcSystemMenuMapper ucSystemMenuMapper;


    @Override
    public UcUser getUser(String username) {
        return ucUserMapper.getUser(username);
    }

    @Override
    public List<UcUserRole> getRoles(Integer userId) {
        return ucUserRoleMapper.getRoles(userId);
    }

    @Override
    public ResponsePageResult<List<UserFindListVo>> getUserFindListVo(String systemCode, String username, int page, int size) {
        Page pages = PageHelper.startPage(page, size); // 下面的一行接上查询的接口
        List<UserFindListVo> data = ucUserMapper.getUserFindListVo(username);
        return new ResponsePageResult<List<UserFindListVo>>(0, page, size, pages.getTotal(), data);
    }

    @Override
    public ResponseResult<List<TreeListVo>> getTreeListBySystemCode(String systemCode) {
        return new ResponseResult<>(0,ucSystemMenuMapper.getTreeList(systemCode));
    }
}
